﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<link href="../assets/css/plugins/jsTree/style.min.css" rel="stylesheet">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="../assets/css/plugins/treeview/bootstrap-treeview.css" rel="stylesheet">
<link href="../assets/img/validate/validate.css" rel="stylesheet">
<style type="text/css">
#configWindow .modal-body{padding: 0;}
#configWindow .list-group{margin-bottom: 0;}
.system-box .right-side{width: 100%;}
.btnBg, .iconList .fa{
    display: inline-block;
    margin-right: 10px;
    cursor: pointer;
}
.btnBg{
	position: relative;
	top: 3px;
	width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
}
.btnBg.check{
	top: 0px;
}
.btnBg i{
	display: none;
}
.btnBg.check i{
	display: inline;
}
.iconList .fa{
	padding: 0 3px 1px 3px;
    margin: 0 10px 0 -1px;
}
.iconList .fa.check{
	color: #f00;
	border-bottom: 1px solid;
}

.list-group-item{
	padding: 4px 5px;
	white-space:nowrap;
}    

@media (min-width: 768px) {
	.modal-dialog {
		width: 768px;
		margin: 30px auto;
	}
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
	<div class="system-box">
		<div class="right-side">
			<div class="btns-container">
				<div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
					<form id="checkButtonForm" method="get" action="#">
					<div class="modal-dialog">
						<div class="modal-content animated bounceInRight">
							<div class="modal-header">
								<span class="editTitle">新增按钮</span>
								<button type="button" class="close" data-dismiss="modal">
									<span aria-hidden="true">&times;</span>
									<span class="sr-only">关闭</span>
                                </button>
							</div>
							<div id="message" style="display: none"></div>
							<div class="modal-body">
								<table class="module-info" cellpadding="0" cellspacing="0">
									<thead></thead>
									<tbody>
										<tr>
											<td>
												<div class="form-group">
                                					<label class="control-label">按钮名称&nbsp;&nbsp;</label>
                                					<input id="bname" name="bname" placeholder="请输入按钮名称" 
                                						datacol="yes" err="按钮名称" checkexpession="NotNull"
                                						maxlength="10" type="text" class="form-control input-w288 required" />
                            					</div>
											</td>
											<td>
                            					<div class="form-group">
                                					<label class="control-label">　按钮ID&nbsp;&nbsp;</label>
                                					<input id="btnid" name="btnid" placeholder="请输入按钮ID" 
                                						datacol="yes" err="按钮ID" checkexpession="NotNull"
                                						maxlength="20" type="text" class="form-control input-w288 required" />
                            					</div>
											</td>
										</tr>
										<tr>
											<td>
												<div class="form-group">
                                					<label class="control-label">按钮类型&nbsp;&nbsp;</label>
                                					<select class="form-control m-b input-w288" id="btntype">
                                        				<option value="0">系统</option>
                                        				<option value="1">其他</option>
                                    				</select>
                            					</div>
											</td>
											<td>
												<div class="form-group">
                                					<label class="control-label">显示顺序&nbsp;&nbsp;</label>
                                					<input id="bsort" type="number" name="bsort" class="form-control input-w288" />
                            					</div>
											</td>
										</tr>
										
										<tr>
											<td>
												<div class="form-group">
													<label class="control-label">是否有效&nbsp;&nbsp;</label>
													<div class="checkbox i-checks label-inline">
														<label class="effective">
															<input id="beffective" type="checkbox" checked="">
														</label>
	                                        		</div>
                                        		</div>
											</td>
											<td>
                                				<div class="form-group">
                                					<label class="control-label">弹窗类型&nbsp;&nbsp;</label>
                                    				<select class="form-control m-b input-w288" id="functiontype">
                                        				<option value="">无</option>
                                    				</select>
                                				</div>
											</td>
										</tr>
																				
										<tr>
											<td colspan="2">
												<div class="form-group">
                                					<label class="control-label">背景颜色&nbsp;&nbsp;</label>
                                					<div class="colorList" style="display: inline-block;">
                                						<span class="btnBg btn-success">
                                							<i class="fa fa-check"></i>
                                						</span>
	                                					<span class="btnBg btn-primary">
	                                						<i class="fa fa-check"></i>
	                                					</span>
	                                					<span class="btnBg btn-default">
	                                						<i class="fa fa-check"></i>
	                                					</span>
	                                					<span class="btnBg btn-info">
	                                						<i class="fa fa-check"></i>
	                                					</span>
	                                					<span class="btnBg btn-warning">
	                                						<i class="fa fa-check"></i>
	                                					</span>
	                                					<span class="btnBg btn-danger">
	                                						<i class="fa fa-check"></i>
	                                					</span>
                                					</div>
												</div>
											</td>
										</tr>
										
										<tr>
											<td colspan="2">
												<div class="form-group">
													<label class="control-label">按钮图标&nbsp;&nbsp;</label>
													<div class="iconList" style="display: inline;">
														<i class="fa fa-refresh"></i>
														<i class="fa fa-plus"></i>
														<i class="fa fa-edit"></i>
														<i class="fa fa-cog"></i>
														<i class="fa fa-minus"></i>
														<i class="fa fa-eraser"></i>
														<i class="fa fa-users"></i>
														<i class="fa fa-exclamation-triangle"></i>
														<i class="fa fa-download"></i>
														<i class="fa fa-folder-open-o"></i>
														<i class="fa fa-upload"></i>
														<i class="fa fa-cloud-download"></i>
														<i class="fa fa-search"></i>
														<i class="fa fa-files-o"></i>
														<i class="fa fa-floppy-o"></i>
													</div>
												</div>
											</td>
										</tr>
																				
										<tr>
											<td colspan="2">
												<div class="form-group">
													<label class="control-label label-float">备注说明&nbsp;&nbsp;</label>
													<textarea id="bexplain" name="bexplain" style="margin-left: 3px;" 
														class="form-control input-textarea input-w660" placeholder="在此输入备注说明"></textarea>
												</div>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
							<div class="modal-footer">
								<button type="button" id="addButtonBtn" class="btn btn-primary">保存</button>
								<button type="button" class="btn btn-white closeBtn" data-dismiss="modal">关闭</button>
							</div>
						</div>
					</div>
					</form>
				</div>
				
				<div class="modal inmodal" id="configWindow" tabindex="-1" role="dialog" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content animated bounceInRight">
							<div class="modal-header">
								<span>按钮配置</span>
								<button type="button" class="close" data-dismiss="modal">
									<span aria-hidden="true">&times;</span>
									<span class="sr-only">关闭</span>
                                </button>
							</div>
							<div class="modal-body">
								<div class="tips">
									<i class="fa fa-lightbulb-o"></i>
									温馨提示：点击模块中的多选框，可以同时保存多个模块的按钮配置,而且保存时，至少要选中一个
								</div>
								<div class="btn-config-box">
									<div class="box-title">
										<div class="left-side">系统模块</div>
										<div class="right-side">
											<span class="right-side-title">当前模块：</span><span id="chooseModule"></span>
											<button type="button" id="chooseAll" class="btn btn-success">全选</button>
										</div>
									</div>
									<div class="btn-config-tree">
										
									</div>
									<div class="btn-config-list" id="btnConfigList">
										
									</div>
								</div>
							</div>
							<div class="modal-footer">
								<button type="button" id="saveConfigBtn" class="btn btn-primary">保存</button>
								<button type="button" class="btn btn-white closeBtn" data-dismiss="modal">关闭</button>
							</div>
						</div>
					</div>
				</div>
				
			</div>
			
			<div class="right-content-box">
				<div class="ibox-content">
					<table class="footable table table-stripped">
						<thead></thead>
						<tbody id="pageList"></tbody>
					</table>
                </div>
			</div>
		</div>
	</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
<script src="../assets/js/plugins/jsTree/jstree.min.js"></script>
<script src="../assets/js/plugins/treeview/bootstrap-treeview.js"></script>
<script src="../assets/js/plugins/footable/footable.all.min.js"></script>
<script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/lodash.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
<script src="../assets/img/validate/learunui-validator.js"></script>
<script type="application/javascript">
	$(document).ready(function(){
		//用于保存预览样式列表
		var previewList = [];
		
		//限制textarea输入字数
		commonUtil.inputLimitForId('bexplain',50);
		
		//初始化多选框
		$(".i-checks").iCheck({
			checkboxClass:"icheckbox_square-green",
		});
		
		//用于记录当前选中节点id
		var mid = 0;
		//用于记录当前选中按钮id
		var bid = 0;
		//用于判断是新增还是编辑(新增是true,编辑是false)
		var isCreate = true;
		//用于记录当前选中节点类型
		var mtype = 0;
		//用于记录当前选中节点是否可用
		var meffective = true;
		//用于记录配置弹窗中选中的节点及对应按钮集合
		var bootArr = [];
		//用于存储所有按钮的对象
		var btnList = [];
		//用于存储初始化按钮配置
		var initBtnList = [];
		//当前选中的模块id(配置弹窗的树形目录)
		var bootMid = 0;
	    //模块ID
		var ModuleID = Y.getUrlParam("ModuleID");
		//用于记录配置弹窗的目录树的数据
		var bootData = {};
		var bootTree = [];
		
		//获取按钮配置
		commonUtil.getJson('../assets/json/btnConfig.json', {}, function (data) {
			//弹窗绑定部分
			var html = '';
			data.popUp.map(function (item) {
				html += '<option value="' + item.Id + '">' + item.text + '</option>';
			});
			$('#functiontype').append(html);
		});
		
		//选择按钮
		$('#btnConfigList').on('click','.btn-container',function(){
			//处理样式
			if($(this).hasClass('check')){
				$(this).removeClass('check');
			}else{
				$(this).addClass('check');
			}
			
			//处理临时数组
			var tempCount = 0;
			//当前按钮id
			var tempId = parseInt($(this).find('.bid').val());
			//当前按钮对象
//				var tempObj = _.find(btnList,function(item){return item.ID == tempId});
			//当前模块的按钮列表
			var moduleBtnList = _.find(initBtnList,function(item){return item.ModuleID == bootMid});
			moduleBtnList = Y.checkNull(moduleBtnList) ? [] : moduleBtnList['BtnList'];
			//临时存储列表长度，避免移除元素后，数组长度改变影响判断
			var tempLength = moduleBtnList.length;
			for(var i = 0; i < tempLength; i++){
//					if(moduleBtnList[i]['ID'] == tempId){
				if(moduleBtnList[i] == tempId){
					//移除
					_.pullAt(moduleBtnList,i);
					break;
				}
				tempCount++;
			}
			if(tempCount == tempLength){
				//添加
//					moduleBtnList.push(tempObj);
				moduleBtnList.push(tempId);
			}
//			console.log(initBtnList);
		});
		
		//全选按钮
		$('#chooseAll').on('click',function(){
			//当前模块的按钮列表
			var moduleBtnList = _.find(initBtnList,function(item){return item.ModuleID == bootMid});
			moduleBtnList = moduleBtnList['BtnList'];
			//先清空处理
			moduleBtnList.length = 0;
			
			if($('.btn-container').size() == $('.btn-container.check').size()){
				$('.btn-container').removeClass('check');
			}else{
				$('.btn-container').addClass('check');
				
				btnList.map(function(item){
//						moduleBtnList.push(item);
					moduleBtnList.push(item.ID);
				});
			}
//			console.log(initBtnList);
		});
		
		var initConfigTree = function(){
			$('.btn-config-tree').treeview({
      			data: bootTree,
      			showCheckbox: true,
      			uncheckedIcon: 'glyphicon glyphicon-unchecked',
    		}).on('nodeChecked',function(event, node){
    			//选中模块节点
    			var count = 0;
    			for(var i = 0; i < bootArr.length; i++){
    				if(bootArr[i].ID == node.data.ID){
    					break;
    				}
    				count++;
    			}
    			if(count == bootArr.length){
    				bootArr.push(node.data);
    			}
    		}).on('nodeUnchecked',function(event, node){
    			//取消选中模块节点
    			for(var i = 0; i < bootArr.length; i++){
    				if(bootArr[i].ID == node.data.ID){
    					_.pullAt(bootArr, i);
    					break;
    				}
    			}
    		}).on('nodeSelected',function(event, node){
    			var node_data = node.data;
    			bootMid = node_data.ID;
    			$('#chooseModule').text(node.text);
    			
    			btnList = [];
    			$('#btnConfigList').empty();
    			if(node_data.Type == 2){
    				Y.API2('Button','GetList',{},function(data){
    					if(data.Success == false){
    						swal(data.Message, '', 'error');
    					}else{
    						var loginJson = window.sessionStorage.getItem('login-info');
							var btnStyle = 'btn-Style1';
							if(!Y.checkNull(loginJson)){
								loginJson = JSON.parse(loginJson);
								loginJson.ConfigList.map(function(item){
									if(item.dictValue == 'btn-Style')
										btnStyle = item.Value;
								})
							}
    						data.map(function(item){
        						btnList.push(item);
								var html  = '<div class="btn-container">';
									html += 	'<button type="button" class="btn ' + (btnStyle == 'btn-Style1' ? '' : 'btn-outline ') + item.BackColor +'">';
									html +=			'<input type="hidden" class="bid" value="'+ item.ID +'" />';
									if(!Y.checkNull(item.Icon) && btnStyle == 'btn-Style1'){
										html += '<i class="' + item.Icon + '"></i>&nbsp;&nbsp;' + item.BtnName;
									}else{
										html += item.BtnName;
									}
									html +=		'</button>';
									html +=		'<div class="ischeck">'
									html +=			'<i class="fa fa-check '+ (btnStyle == 'btn-Style1' ? '' : item.BackColor.replace('btn','text')) +'"></i>';
									html +=		'</div>';
									html +=	'</div>';
								$('#btnConfigList').append(html);
							});
							
							Y.API2('Button','GetSetButtonList',{
        						moduleId: bootMid
        					},function(result){
        						if(result.Success == false){
        							swal(result.Message, '', 'error');
        						}else{	
									//当前模块的按钮列表
									var moduleBtnList = _.find(initBtnList,function(item){return item.ModuleID == bootMid});
									if(Y.checkNull(moduleBtnList)){
										initBtnList.push({
											ModuleID: bootMid,
											BtnList: []
										});
										moduleBtnList = _.find(initBtnList,function(item){return item.ModuleID == bootMid});
									}
									moduleBtnList = moduleBtnList['BtnList'];
									$('.btn-container').each(function(){
										var $this = $(this);
										moduleBtnList.map(function(item,i){
											var tempId = parseInt($this.find('.bid').val());
//												if(tempId == item.ID){
											if(tempId == item){
												$this.addClass('check');
											}
										})
									})
								}
        					})
    					}

    				})
    				
    			}
    			$('.btn-config-tree').treeview('checkNode', [node.nodeId]);
    		});
		}
		
		//加载导航列表
		var loadList = function() {
			//调用加载层
			layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
			Y.API2('Module', 'GetList', {}, function(data) {
				//关闭加载层
				layer.closeAll('dialog');
				
				//用于记录外层目录树的json
				var treeData = {};
				
				if(!Y.checkNull(data) && data.length > 0){
					//json处理
					data.map(function(item,i){
						treeData.text = item.ModuleName;
						treeData.data = {
							Grade: item.Grade,
							ID: item.ID,
							SuperiorModule: item.SuperiorModule,
							Type: item.Type
						};
						
						bootData.text = treeData.text;
						bootData.data = treeData.data;
						
						if(item.Childrens.length > 0)
							bootData.nodes = getBootNode(item.Childrens);
					})
					
					//配置弹出框的树形机构
					bootTree.push(bootData);
					initConfigTree();
				}
			});
		}
		loadList();
		
		//初始化配置左侧子菜单
		var getBootNode = function(data){
			var tempArr = [];
			data.map(function(item,i){
				var temp = {};
				temp.text = item.ModuleName;
				temp.data = {
					Grade: item.Grade,
					ID: item.ID,
					SuperiorModule: item.SuperiorModule,
					Type: item.Type
				};
				if(!Y.checkNull(item.Childrens) && item.Childrens.length > 0){
					temp.nodes = getBootNode(item.Childrens);
				}
				tempArr.push(temp);
			});
			return tempArr;
		}
		
		//获取所有按钮
		var getButtonList = function(moduleID){
			if($('.footable thead').children().size() == 0)
				tableControl.initThead2('.footable',['编号','按钮名称','按钮ID','排序','状态']);
			
			Y.API2('Button','GetList',{ModuleID: moduleID},function(data){
				if(data.Success == false){
					swal(data.Message, '', 'error');
				}else{
					var tBody = [];
				    if (!Y.checkNull(data)) {
						data.map(function(item,i){
							var tempTr = {
								trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd' ),
								children: [
									{tdText: item.ID, c:0 , r:0, tdHtml:'', tdId:'', tdClass:'bid'},
									{tdText: (item.BtnName || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
									{tdText: (item.BtnID || ' '), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
									{tdText: (item.Sort), c:0 , r:0, tdHtml:'', tdId:'', tdClass:''},
									{tdText: (item.IsEffective ? ' 有效' : ' 无效'), c:0 , r:0, tdHtml: ('<i class="fa fa-'+ (item.IsEffective ? 'check text-navy' : 'times text-danger') +'"></i>'), tdId:'', tdClass:''},
								]
							};
							tBody.push(tempTr);
						})
					}
				    tableControl.initTbody('.footable',(tBody.length > 0 ? tBody : null),4,null);
					bid = 0;
					$('#editBtn').attr('disabled','disabled');
					$('#deleteBtn').attr('disabled','disabled');
				}
			});
		}
		getButtonList(0);
		
		//选中按钮信息
		$('#pageList').on('click', 'tr', function(){
			var tempId = parseInt($(this).find('.bid').text());
			if(bid == tempId)
				return false;
			//选中时信息获取
			bid = tempId;
			//解除禁止编辑和删除按钮
			if(!isNaN(bid)){
				$('#editBtn').removeAttr('disabled');
				$('#deleteBtn').removeAttr('disabled');
			}
			//选中样式切换
			$('#pageList tr').removeClass('check');
			$(this).addClass('check');
		});
		
		//检验提交信息
		$('#addButtonBtn').click(function(){
			if (!CheckDataValid('#checkButtonForm')) {
                return false;
            }
			if($('.colorList .check').size() == 0){
				swal('请选择背景颜色');
				return false;
			}
			var BackColor = $('.colorList .check').attr('class').replace('check','').replace('btnBg','').trim();
			var Icon = '';
			if($('.iconList .check').size() > 0){
				Icon = $('.iconList .check').attr('class').replace('check','').trim();
			}
			//检验通过后执行新增或者编辑
			var deal = '';
			var successText = '';
			if(isCreate){
				deal = 'Create';
				successText = '新增成功';
			}else{
				deal = 'Modify';
				successText = '编辑成功';
			}
			
			Y.API2('Button', deal, {
				ID: bid,
				BtnName: $('#bname').val(),
				CssID: $('#bstyle').val(),
				BtnID: $('#btnid').val(),
				Sort: $('#bsort').val(),
				IsEffective: $('#beffective').is(':checked'),
				Memo: $('#bexplain').val(),
				MoldID: $('#functiontype').val(),
				BtnType: $('#btntype').val(),
				BackColor: BackColor,
				Icon: Icon
			},function(data){
				if(data.Success == false){
					swal(data.Message, '', 'error');
				}else{
					swal(successText, '', 'success');
					$('.closeBtn').click();
					getButtonList(mid);
				}
			})
		})
		
		var loadIndex = function () {
		    Y.API2('Common', 'GetSort', { "tableName": "sys_button", "sortName": "Sort" }, function (data) {
		        if (data.Success == false) {
		            //layer.msg(data.Message);
		        } else {
		            $("#bsort").val(data + 1);
		            $("#bsort").attr("readonly", true);
		        }
		    });
		}
		
		//保存配置
		$('#saveConfigBtn').on('click',function(){
			if(bootArr.length == 0){
				swal('至少要勾选一个模块');
				return false;
			}
			
			//提交配置的列表
			var submitList = [];
			bootArr.map(function(item,i){
				var tempObj = _.find(initBtnList,function(it){return it.ModuleID == item.ID});
				submitList.push(tempObj);
			});
//				console.log('initBtnList',initBtnList);
//				console.log('submitList',submitList);
//				return false;
			Y.API2('Button','InitModuleButton',{
				list:submitList
			},function(data){
				if(data.Success == false){
					swal(data.Message, '', 'error');
				}else{
					swal('保存成功', '', 'success')
					$('.closeBtn').click();
					getButtonList(mid);
				}
			});
		});
		
	    //获取按钮
		commonUtil.loadBtnList(ModuleID,function(){
			//禁止编辑和删除
			$('#editBtn').attr('disabled','disabled');
			$('#deleteBtn').attr('disabled','disabled');
		    rScroll();
		});
		
		//刷新按钮
		$('.btns-container').on('click', '#refreshBtn', function () {
		    //loadList();
		    getButtonList(mid);
		});

		commonUtil.initDeleteBtnEvent({
		    callBack: function () {
		        Y.API2('Button', 'Remove', { ID: bid }, function (data) {
		            layer.closeAll('dialog');
		            if (data.Success == false) {
		                swal('删除失败', data.Message, 'error');
		            } else {
		                swal('删除成功', '该信息已被你永久删除', 'success');
		                getButtonList(mid);
		            }
		        });
		    }
		});

		//添加按钮
		$('.btns-container').on('click', '#addBtn', function () {
		    $('.editTitle').text('新增按钮');
		    isCreate = true;
		    //需要先初始化表单
		    $(':input', '#checkButtonForm').not(':button, :submit, :reset').val('');
		    if (!$('#beffective').is(':checked'))
		        $('#beffective').parent().click();
		    $('#bstyle').val('0');
		    $('#btntype').val('0');
		    $('.colorList .btnBg').removeClass('check');
		    $('.iconList .fa').removeClass('check');
		    loadIndex();
		});

		//编辑按钮
		$('.btns-container').on('click', '#editBtn', function () {
		    $('.editTitle').text('编辑按钮');
		    isCreate = false;
		    if (bid == 0) {
		        return false;
		    }

		    //需要表单填充原有的数据
		    layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
		    Y.API2('Button', 'GetID', {
		        BtnID: bid
		    }, function (data) {
		        layer.closeAll('dialog');
		        if (data.Success == false) {
		            swal(data.Message, '', 'error');
		        } else {
		            $('#bname').val(data.BtnName);
		            $('#bstyle').val(data.CssID);
		            $('#btnid').val(data.BtnID);
		            $('#bsort').val(data.Sort);
		            if ($('#beffective').is(':checked') != data.IsEffective) {
		                $('#beffective').parent().click();
		            }
		            $('#bexplain').val(data.Memo || '');
		            $('#btntype').val(data.BtnType ? '1' : '0');
		            $('#functiontype').val(data.MoldID || '');
		            
		            $('.colorList .btnBg').removeClass('check');
		            $('.iconList .fa').removeClass('check');
		            if(!Y.checkNull(data.BackColor)){
		            	$('.colorList .btnBg').each(function(){
		            		if($(this).attr('class').indexOf(data.BackColor) > -1){
		            			$(this).addClass('check');
		            			return false;
		            		}
		            	})
		            }
		            if(!Y.checkNull(data.Icon)){
		            	$('.iconList .fa').each(function(){
		            		if($(this).attr('class').indexOf(data.Icon) > -1){
		            			$(this).addClass('check');
		            			return false;
		            		}
		            	})
		            }
		        }
		    });
		});
		
		//选择背景色
		$('.colorList').on('click','.btnBg',function(){
			$('.colorList .btnBg').removeClass('check');
			$(this).addClass('check');
		});
		
		//选择按钮图标
		$('.iconList').on('click','.fa',function(){
			if($(this).hasClass('check')){
				$(this).removeClass('check');
				return false;
			}
			$('.iconList .fa').removeClass('check');
			$(this).addClass('check');
		})

		//配置按钮
		$('.btns-container').on('click', '#configBtn', function () {
		    var isSelect = false;
		    initConfigTree();
		    //获取已绑定的按钮
		    layer.msg('玩命加载中……', {icon: 16, shade: 0.5, time:0, maxWidth:200});
		    Y.API2('Button', 'GetModuleButton', {

		    }, function (data) {
		        layer.closeAll('dialog');
		        if (data.Success == false) {
		            swal(data.Message, '', 'error');
		        } else {
		            initBtnList = data;
		            //console.log('initBtnList',initBtnList);
		            var templist = $('.btn-config-tree').treeview('getEnabled');
		            templist.map(function(item){
		                data.map(function(item2){
		                   	if(item.data.ID == item2.ModuleID){
		                   		$('.btn-config-tree').treeview('checkNode', [item.nodeId]);
								if(!isSelect){
									isSelect = true;
									$('.btn-config-tree').treeview('unselectNode', [item.nodeId, { silent: true }]);
									$('.btn-config-tree').treeview('selectNode', [item.nodeId]);
								}
		                   	}
		                })
		            })
		        }
		    });
		});
	})
</script>
</asp:Content>

